<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Arcsine Distribution</title>
<link rel="stylesheet" href="../../../math.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../index.html" title="Math Toolkit 3.3.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="../dists.html" title="Distributions">
<link rel="next" href="bernoulli_dist.html" title="Bernoulli Distribution">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../dists.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../dists.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="bernoulli_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="math_toolkit.dist_ref.dists.arcine_dist"></a><a class="link" href="arcine_dist.html" title="Arcsine Distribution">Arcsine Distribution</a>
</h4></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">distributions</span><span class="special">/</span><span class="identifier">arcsine</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">math</span><span class="special">{</span>

 <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">RealType</span> <span class="special">=</span> <span class="keyword">double</span><span class="special">,</span>
           <span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a>   <span class="special">=</span> <a class="link" href="../../pol_ref/pol_ref_ref.html" title="Policy Class Reference">policies::policy&lt;&gt;</a> <span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">arcsine_distribution</span><span class="special">;</span>

<span class="keyword">typedef</span> <span class="identifier">arcsine_distribution</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">arcsine</span><span class="special">;</span> <span class="comment">// double precision standard arcsine distribution [0,1].</span>

<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">RealType</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">arcsine_distribution</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
   <span class="keyword">typedef</span> <span class="identifier">RealType</span>  <span class="identifier">value_type</span><span class="special">;</span>
   <span class="keyword">typedef</span> <span class="identifier">Policy</span>    <span class="identifier">policy_type</span><span class="special">;</span>

   <span class="comment">// Constructor from two range parameters, x_min and x_max:</span>
   <span class="identifier">arcsine_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">x_min</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">x_max</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>

   <span class="comment">// Range Parameter accessors:</span>
   <span class="identifier">RealType</span> <span class="identifier">x_min</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
   <span class="identifier">RealType</span> <span class="identifier">x_max</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
          The class type <code class="computeroutput"><span class="identifier">arcsine_distribution</span></code>
          represents an <a href="http://en.wikipedia.org/wiki/arcsine_distribution" target="_top">arcsine</a>
          <a href="http://en.wikipedia.org/wiki/Probability_distribution" target="_top">probability
          distribution function</a>. The arcsine distribution is named because
          its CDF uses the inverse sin<sup>-1</sup> or arcsine.
        </p>
<p>
          This is implemented as a generalized version with support from <span class="emphasis"><em>x_min</em></span>
          to <span class="emphasis"><em>x_max</em></span> providing the 'standard arcsine distribution'
          as default with <span class="emphasis"><em>x_min = 0</em></span> and <span class="emphasis"><em>x_max = 1</em></span>.
          (A few make other choices for 'standard').
        </p>
<p>
          The arcsine distribution is generalized to include any bounded support
          <span class="emphasis"><em>a &lt;= x &lt;= b</em></span> by <a href="http://reference.wolfram.com/language/ref/ArcSinDistribution.html" target="_top">Wolfram</a>
          and <a href="http://en.wikipedia.org/wiki/arcsine_distribution" target="_top">Wikipedia</a>,
          but also using <span class="emphasis"><em>location</em></span> and <span class="emphasis"><em>scale</em></span>
          parameters by <a href="http://www.math.uah.edu/stat/index.html" target="_top">Virtual
          Laboratories in Probability and Statistics</a> <a href="http://www.math.uah.edu/stat/special/Arcsine.html" target="_top">Arcsine
          distribution</a>. The end-point version is simpler and more obvious,
          so we implement that. If desired, <a href="http://en.wikipedia.org/wiki/arcsine_distribution" target="_top">this</a>
          outlines how the <a class="link" href="beta_dist.html" title="Beta Distribution">Beta
          Distribution</a> can be used to add a shape factor.
        </p>
<p>
          The <a href="http://en.wikipedia.org/wiki/Probability_density_function" target="_top">probability
          density function PDF</a> for the <a href="http://en.wikipedia.org/wiki/arcsine_distribution" target="_top">arcsine
          distribution</a> defined on the interval [<span class="emphasis"><em>x_min, x_max</em></span>]
          is given by:
        </p>
<div class="blockquote"><blockquote class="blockquote"><p>
            <span class="serif_italic">f(x; x_min, x_max) = 1 /(π⋅√((x - x_min)⋅(x_max
            - x_min))</span>
          </p></blockquote></div>
<p>
          For example, <a href="http://www.wolframalpha.com/" target="_top">Wolfram Alpha</a>
          arcsine distribution, from input of
        </p>
<pre class="programlisting"><span class="identifier">N</span><span class="special">[</span><span class="identifier">PDF</span><span class="special">[</span><span class="identifier">arcsinedistribution</span><span class="special">[</span><span class="number">0</span><span class="special">,</span> <span class="number">1</span><span class="special">],</span> <span class="number">0.5</span><span class="special">],</span> <span class="number">50</span><span class="special">]</span>
</pre>
<p>
          computes the PDF value
        </p>
<pre class="programlisting"><span class="number">0.63661977236758134307553505349005744813783858296183</span>
</pre>
<p>
          The Probability Density Functions (PDF) of generalized arcsine distributions
          are symmetric U-shaped curves, centered on <span class="emphasis"><em>(x_max - x_min)/2</em></span>,
          highest (infinite) near the two extrema, and quite flat over the central
          region.
        </p>
<p>
          If random variate <span class="emphasis"><em>x</em></span> is <span class="emphasis"><em>x_min</em></span>
          or <span class="emphasis"><em>x_max</em></span>, then the PDF is infinity. If random variate
          <span class="emphasis"><em>x</em></span> is <span class="emphasis"><em>x_min</em></span> then the CDF is zero.
          If random variate <span class="emphasis"><em>x</em></span> is <span class="emphasis"><em>x_max</em></span>
          then the CDF is unity.
        </p>
<p>
          The 'Standard' (0, 1) arcsine distribution is shown in blue and some generalized
          examples with other <span class="emphasis"><em>x</em></span> ranges.
        </p>
<div class="blockquote"><blockquote class="blockquote"><p>
            <span class="inlinemediaobject"><img src="../../../../graphs/arcsine_pdf.svg" align="middle"></span>

          </p></blockquote></div>
<p>
          The Cumulative Distribution Function CDF is defined as
        </p>
<div class="blockquote"><blockquote class="blockquote"><p>
            <span class="serif_italic">F(x) = 2⋅arcsin(√((x-x_min)/(x_max - x))) /
            π</span>
          </p></blockquote></div>
<div class="blockquote"><blockquote class="blockquote"><p>
            <span class="inlinemediaobject"><img src="../../../../graphs/arcsine_cdf.svg" align="middle"></span>

          </p></blockquote></div>
<h6>
<a name="math_toolkit.dist_ref.dists.arcine_dist.h0"></a>
          <span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.constructor"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.constructor">Constructor</a>
        </h6>
<pre class="programlisting"><span class="identifier">arcsine_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">x_min</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">x_max</span><span class="special">);</span>
</pre>
<p>
          constructs an arcsine distribution with range parameters <span class="emphasis"><em>x_min</em></span>
          and <span class="emphasis"><em>x_max</em></span>.
        </p>
<p>
          Requires <span class="emphasis"><em>x_min &lt; x_max</em></span>, otherwise <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
          is called.
        </p>
<p>
          For example:
        </p>
<pre class="programlisting"><span class="identifier">arcsine_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">myarcsine</span><span class="special">(-</span><span class="number">2</span><span class="special">,</span> <span class="number">4</span><span class="special">);</span>
</pre>
<p>
          constructs an arcsine distribution with <span class="emphasis"><em>x_min = -2</em></span>
          and <span class="emphasis"><em>x_max = 4</em></span>.
        </p>
<p>
          Default values of <span class="emphasis"><em>x_min = 0</em></span> and <span class="emphasis"><em>x_max =
          1</em></span> and a <code class="computeroutput"> <span class="keyword">typedef</span> <span class="identifier">arcsine_distribution</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">arcsine</span><span class="special">;</span></code>
          mean that
        </p>
<pre class="programlisting"><span class="identifier">arcsine</span> <span class="identifier">as</span><span class="special">;</span>
</pre>
<p>
          constructs a 'Standard 01' arcsine distribution.
        </p>
<h6>
<a name="math_toolkit.dist_ref.dists.arcine_dist.h1"></a>
          <span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.parameter_accessors"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.parameter_accessors">Parameter
          Accessors</a>
        </h6>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">x_min</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">RealType</span> <span class="identifier">x_max</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
          Return the parameter <span class="emphasis"><em>x_min</em></span> or <span class="emphasis"><em>x_max</em></span>
          from which this distribution was constructed.
        </p>
<p>
          So, for example:
        </p>
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">arcsine_distribution</span><span class="special">;</span>

<span class="identifier">arcsine_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">as</span><span class="special">(</span><span class="number">2</span><span class="special">,</span> <span class="number">5</span><span class="special">);</span> <span class="comment">// Constructs a double arcsine distribution.</span>
<span class="identifier">BOOST_MATH_ASSERT</span><span class="special">(</span><span class="identifier">as</span><span class="special">.</span><span class="identifier">x_min</span><span class="special">()</span> <span class="special">==</span> <span class="number">2.</span><span class="special">);</span>  <span class="comment">// as.x_min() returns 2.</span>
<span class="identifier">BOOST_MATH_ASSERT</span><span class="special">(</span><span class="identifier">as</span><span class="special">.</span><span class="identifier">x_max</span><span class="special">()</span> <span class="special">==</span> <span class="number">5.</span><span class="special">);</span>   <span class="comment">// as.x_max()  returns 5.</span>
</pre>
<h5>
<a name="math_toolkit.dist_ref.dists.arcine_dist.h2"></a>
          <span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.non_member_accessor_functions"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.non_member_accessor_functions">Non-member
          Accessor Functions</a>
        </h5>
<p>
          All the <a class="link" href="../nmp.html" title="Non-Member Properties">usual non-member accessor
          functions</a> that are generic to all distributions are supported:
          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.quantile">Quantile</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.hazard">Hazard Function</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.chf">Cumulative Hazard Function</a>,
          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.mean">mean</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.median">median</a>,
          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.mode">mode</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.variance">variance</a>,
          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.skewness">skewness</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.kurtosis">kurtosis</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.kurtosis_excess">kurtosis_excess</a>,
          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.range">range</a> and <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.support">support</a>.
        </p>
<p>
          The formulae for calculating these are shown in the table below, and at
          <a href="http://mathworld.wolfram.com/arcsineDistribution.html" target="_top">Wolfram
          Mathworld</a>.
        </p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
            There are always <span class="bold"><strong>two</strong></span> values for the
            <span class="bold"><strong>mode</strong></span>, at <span class="emphasis"><em>x_min</em></span>
            and at <span class="emphasis"><em>x_max</em></span>, default 0 and 1, so instead we raise
            the exception <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
            At these extrema, the PDFs are infinite, and the CDFs zero or unity.
          </p></td></tr>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.arcine_dist.h3"></a>
          <span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.applications"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.applications">Applications</a>
        </h5>
<p>
          The arcsine distribution is useful to describe <a href="http://en.wikipedia.org/wiki/Random_walk" target="_top">Random
          walks</a>, (including drunken walks) <a href="http://en.wikipedia.org/wiki/Brownian_motion" target="_top">Brownian
          motion</a>, <a href="http://en.wikipedia.org/wiki/Wiener_process" target="_top">Weiner
          processes</a>, <a href="http://en.wikipedia.org/wiki/Bernoulli_trial" target="_top">Bernoulli
          trials</a>, and their application to solve stock market and other
          <a href="http://en.wikipedia.org/wiki/Gambler%27s_ruin" target="_top">ruinous gambling
          games</a>.
        </p>
<p>
          The random variate <span class="emphasis"><em>x</em></span> is constrained to <span class="emphasis"><em>x_min</em></span>
          and <span class="emphasis"><em>x_max</em></span>, (for our 'standard' distribution, 0 and
          1), and is usually some fraction. For any other <span class="emphasis"><em>x_min</em></span>
          and <span class="emphasis"><em>x_max</em></span> a fraction can be obtained from <span class="emphasis"><em>x</em></span>
          using
        </p>
<div class="blockquote"><blockquote class="blockquote"><p>
            <span class="serif_italic">fraction = (x - x_min) / (x_max - x_min)</span>
          </p></blockquote></div>
<p>
          The simplest example is tossing heads and tails with a fair coin and modelling
          the risk of losing, or winning. Walkers (molecules, drunks...) moving left
          or right of a centre line are another common example.
        </p>
<p>
          The random variate <span class="emphasis"><em>x</em></span> is the fraction of time spent
          on the 'winning' side. If half the time is spent on the 'winning' side
          (and so the other half on the 'losing' side) then <span class="emphasis"><em>x = 1/2</em></span>.
        </p>
<p>
          For large numbers of tosses, this is modelled by the (standard [0,1]) arcsine
          distribution, and the PDF can be calculated thus:
        </p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">pdf</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">1.</span> <span class="special">/</span> <span class="number">2</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// 0.637</span>
<span class="comment">// pdf has a minimum at x = 0.5</span>
</pre>
<p>
          From the plot of PDF, it is clear that <span class="emphasis"><em>x</em></span> = ½ is the
          <span class="bold"><strong>minimum</strong></span> of the curve, so this is the
          <span class="bold"><strong>least likely</strong></span> scenario. (This is highly
          counter-intuitive, considering that fair tosses must <span class="bold"><strong>eventually</strong></span>
          become equal. It turns out that <span class="emphasis"><em>eventually</em></span> is not
          just very long, but <span class="bold"><strong>infinite</strong></span>!).
        </p>
<p>
          The <span class="bold"><strong>most likely</strong></span> scenarios are towards
          the extrema where <span class="emphasis"><em>x</em></span> = 0 or <span class="emphasis"><em>x</em></span>
          = 1.
        </p>
<p>
          If fraction of time on the left is a ¼, it is only slightly more likely
          because the curve is quite flat bottomed.
        </p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">pdf</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">1.</span> <span class="special">/</span> <span class="number">4</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// 0.735</span>
</pre>
<p>
          If we consider fair coin-tossing games being played for 100 days (hypothetically
          continuously to be 'at-limit') the person winning after day 5 will not
          change in fraction 0.144 of the cases.
        </p>
<p>
          We can easily compute this setting <span class="emphasis"><em>x</em></span> = 5./100 = 0.05
        </p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">cdf</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">0.05</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// 0.144</span>
</pre>
<p>
          Similarly, we can compute from a fraction of 0.05 /2 = 0.025 (halved because
          we are considering both winners and losers) corresponding to 1 - 0.025
          or 97.5% of the gamblers, (walkers, particles...) on the <span class="bold"><strong>same
          side</strong></span> of the origin
        </p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="number">2</span> <span class="special">*</span> <span class="identifier">cdf</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">1</span> <span class="special">-</span> <span class="number">0.975</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// 0.202</span>
</pre>
<p>
          (use of the complement gives a bit more clarity, and avoids potential loss
          of accuracy when <span class="emphasis"><em>x</em></span> is close to unity, see <a class="link" href="../../stat_tut/overview/complements.html#why_complements">why
          complements?</a>).
        </p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="number">2</span> <span class="special">*</span> <span class="identifier">cdf</span><span class="special">(</span><span class="identifier">complement</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">0.975</span><span class="special">))</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// 0.202</span>
</pre>
<p>
          or we can reverse the calculation by assuming a fraction of time on one
          side, say fraction 0.2,
        </p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">quantile</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">1</span> <span class="special">-</span> <span class="number">0.2</span> <span class="special">/</span> <span class="number">2</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">//  0.976</span>

<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">quantile</span><span class="special">(</span><span class="identifier">complement</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">0.2</span> <span class="special">/</span> <span class="number">2</span><span class="special">))</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// 0.976</span>
</pre>
<p>
          <span class="bold"><strong>Summary</strong></span>: Every time we toss, the odds
          are equal, so on average we have the same change of winning and losing.
        </p>
<p>
          But this is <span class="bold"><strong>not true</strong></span> for an an individual
          game where one will be <span class="bold"><strong>mostly in a bad or good patch</strong></span>.
        </p>
<p>
          This is quite counter-intuitive to most people, but the mathematics is
          clear, and gamblers continue to provide proof.
        </p>
<p>
          <span class="bold"><strong>Moral</strong></span>: if you in a losing patch, leave
          the game. (Because the odds to recover to a good patch are poor).
        </p>
<p>
          <span class="bold"><strong>Corollary</strong></span>: Quit while you are ahead?
        </p>
<p>
          A working example is at <a href="../../../../../example/arcsine_example.cpp" target="_top">arcsine_example.cpp</a>
          including sample output .
        </p>
<h5>
<a name="math_toolkit.dist_ref.dists.arcine_dist.h4"></a>
          <span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.related_distributions"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.related_distributions">Related
          distributions</a>
        </h5>
<p>
          The arcsine distribution with <span class="emphasis"><em>x_min = 0</em></span> and <span class="emphasis"><em>x_max
          = 1</em></span> is special case of the <a class="link" href="beta_dist.html" title="Beta Distribution">Beta
          Distribution</a> with α = 1/2 and β = 1/2.
        </p>
<h5>
<a name="math_toolkit.dist_ref.dists.arcine_dist.h5"></a>
          <span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.accuracy"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.accuracy">Accuracy</a>
        </h5>
<p>
          This distribution is implemented using sqrt, sine, cos and arc sine and
          cos trigonometric functions which are normally accurate to a few <a href="http://en.wikipedia.org/wiki/Machine_epsilon" target="_top">machine epsilon</a>.
          But all values suffer from <a href="http://en.wikipedia.org/wiki/Loss_of_significance" target="_top">loss
          of significance or cancellation error</a> for values of <span class="emphasis"><em>x</em></span>
          close to <span class="emphasis"><em>x_max</em></span>. For example, for a standard [0, 1]
          arcsine distribution <span class="emphasis"><em>as</em></span>, the pdf is symmetric about
          random variate <span class="emphasis"><em>x = 0.5</em></span> so that one would expect <code class="computeroutput"><span class="identifier">pdf</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">0.01</span><span class="special">)</span> <span class="special">==</span>
          <span class="identifier">pdf</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">0.99</span><span class="special">)</span></code>. But
          as <span class="emphasis"><em>x</em></span> nears unity, there is increasing <a href="http://en.wikipedia.org/wiki/Loss_of_significance" target="_top">loss
          of significance</a>. To counteract this, the complement versions of
          CDF and quantile are implemented with alternative expressions using <span class="emphasis"><em>cos<sup>-1</sup></em></span>
          instead of <span class="emphasis"><em>sin<sup>-1</sup></em></span>. Users should see <a class="link" href="../../stat_tut/overview/complements.html#why_complements">why
          complements?</a> for guidance on when to avoid loss of accuracy by using
          complements.
        </p>
<h5>
<a name="math_toolkit.dist_ref.dists.arcine_dist.h6"></a>
          <span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.testing"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.testing">Testing</a>
        </h5>
<p>
          The results were tested against a few accurate spot values computed by
          <a href="http://www.wolframalpha.com/" target="_top">Wolfram Alpha</a>, for example:
        </p>
<pre class="programlisting"><span class="identifier">N</span><span class="special">[</span><span class="identifier">PDF</span><span class="special">[</span><span class="identifier">arcsinedistribution</span><span class="special">[</span><span class="number">0</span><span class="special">,</span> <span class="number">1</span><span class="special">],</span> <span class="number">0.5</span><span class="special">],</span> <span class="number">50</span><span class="special">]</span>
<span class="number">0.63661977236758134307553505349005744813783858296183</span>
</pre>
<h5>
<a name="math_toolkit.dist_ref.dists.arcine_dist.h7"></a>
          <span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.implementation"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.implementation">Implementation</a>
        </h5>
<p>
          In the following table <span class="emphasis"><em>a</em></span> and <span class="emphasis"><em>b</em></span>
          are the parameters <span class="emphasis"><em>x_min</em></span> and <span class="emphasis"><em>x_max</em></span>,
          <span class="emphasis"><em>x</em></span> is the random variable, <span class="emphasis"><em>p</em></span> is
          the probability and its complement <span class="emphasis"><em>q = 1-p</em></span>.
        </p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                  <p>
                    Function
                  </p>
                </th>
<th>
                  <p>
                    Implementation Notes
                  </p>
                </th>
</tr></thead>
<tbody>
<tr>
<td>
                  <p>
                    support
                  </p>
                </td>
<td>
                  <p>
                    x ∈ [a, b], default x ∈ [0, 1]
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    pdf
                  </p>
                </td>
<td>
                  <p>
                    f(x; a, b) = 1/(π⋅√(x - a)⋅(b - x))
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    cdf
                  </p>
                </td>
<td>
                  <p>
                    F(x) = 2/π⋅sin<sup>-1</sup>(√(x - a) / (b - a) )
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    cdf of complement
                  </p>
                </td>
<td>
                  <p>
                    2/(π⋅cos<sup>-1</sup>(√(x - a) / (b - a)))
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    quantile
                  </p>
                </td>
<td>
                  <p>
                    -a⋅sin<sup>2</sup>(½π⋅p) + a + b⋅sin<sup>2</sup>(½π⋅p)
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    quantile from the complement
                  </p>
                </td>
<td>
                  <p>
                    -a⋅cos<sup>2</sup>(½π⋅p) + a + b⋅cos<sup>2</sup>(½π⋅q)
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    mean
                  </p>
                </td>
<td>
                  <p>
                    ½(a+b)
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    median
                  </p>
                </td>
<td>
                  <p>
                    ½(a+b)
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    mode
                  </p>
                </td>
<td>
                  <p>
                    x ∈ [a, b], so raises domain_error (returning NaN).
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    variance
                  </p>
                </td>
<td>
                  <p>
                    (b - a)<sup>2</sup> / 8
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    skewness
                  </p>
                </td>
<td>
                  <p>
                    0
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    kurtosis excess
                  </p>
                </td>
<td>
                  <p>
                    -3/2
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    kurtosis
                  </p>
                </td>
<td>
                  <p>
                    kurtosis_excess + 3
                  </p>
                </td>
</tr>
</tbody>
</table></div>
<p>
          The quantile was calculated using an expression obtained by using <a href="http://www.wolframalpha.com/" target="_top">Wolfram Alpha</a> to invert the
          formula for the CDF thus
        </p>
<pre class="programlisting"><span class="identifier">solve</span> <span class="special">[</span><span class="identifier">p</span> <span class="special">-</span> <span class="number">2</span><span class="special">/</span><span class="identifier">pi</span> <span class="identifier">sin</span><span class="special">^-</span><span class="number">1</span><span class="special">(</span><span class="identifier">sqrt</span><span class="special">((</span><span class="identifier">x</span><span class="special">-</span><span class="identifier">a</span><span class="special">)/(</span><span class="identifier">b</span><span class="special">-</span><span class="identifier">a</span><span class="special">)))</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">x</span><span class="special">]</span>
</pre>
<p>
          which was interpreted as
        </p>
<pre class="programlisting"><span class="identifier">Solve</span><span class="special">[</span><span class="identifier">p</span> <span class="special">-</span> <span class="special">(</span><span class="number">2</span> <span class="identifier">ArcSin</span><span class="special">[</span><span class="identifier">Sqrt</span><span class="special">[(-</span><span class="identifier">a</span> <span class="special">+</span> <span class="identifier">x</span><span class="special">)/(-</span><span class="identifier">a</span> <span class="special">+</span> <span class="identifier">b</span><span class="special">)]])/</span><span class="identifier">Pi</span> <span class="special">==</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">MaxExtraConditions</span> <span class="special">-&gt;</span> <span class="identifier">Automatic</span><span class="special">]</span>
</pre>
<p>
          and produced the resulting expression
        </p>
<div class="blockquote"><blockquote class="blockquote"><p>
            <span class="serif_italic">x = -a sin^2((pi p)/2)+a+b sin^2((pi p)/2)</span>
          </p></blockquote></div>
<p>
          Thanks to Wolfram for providing this facility.
        </p>
<h5>
<a name="math_toolkit.dist_ref.dists.arcine_dist.h8"></a>
          <span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.references"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.references">References</a>
        </h5>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
              <a href="http://en.wikipedia.org/wiki/arcsine_distribution" target="_top">Wikipedia
              arcsine distribution</a>
            </li>
<li class="listitem">
              <a href="http://en.wikipedia.org/wiki/Beta_distribution" target="_top">Wikipedia
              Beta distribution</a>
            </li>
<li class="listitem">
              <a href="http://mathworld.wolfram.com/BetaDistribution.html" target="_top">Wolfram
              MathWorld</a>
            </li>
<li class="listitem">
              <a href="http://www.wolframalpha.com/" target="_top">Wolfram Alpha</a>
            </li>
</ul></div>
<h5>
<a name="math_toolkit.dist_ref.dists.arcine_dist.h9"></a>
          <span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.sources"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.sources">Sources</a>
        </h5>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
              <a href="http://estebanmoro.org/2009/04/the-probability-of-going-through-a-bad-patch" target="_top">The
              probability of going through a bad patch</a> Esteban Moro's Blog.
            </li>
<li class="listitem">
              <a href="http://www.gotohaggstrom.com/What%20do%20schmucks%20and%20the%20arc%20sine%20law%20have%20in%20common.pdf" target="_top">What
              soschumcks and the arc sine have in common</a> Peter Haggstrom.
            </li>
<li class="listitem">
              <a href="http://www.math.uah.edu/stat/special/Arcsine.html" target="_top">arcsine
              distribution</a>.
            </li>
<li class="listitem">
              <a href="http://reference.wolfram.com/language/ref/ArcSinDistribution.html" target="_top">Wolfram
              reference arcsine examples</a>.
            </li>
<li class="listitem">
              <a href="http://www.math.harvard.edu/library/sternberg/slides/1180908.pdf" target="_top">Shlomo
              Sternberg slides</a>.
            </li>
</ul></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2006-2021 Nikhar Agrawal, Anton Bikineev, Matthew Borland,
      Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert Holin, Bruno
      Lalande, John Maddock, Evan Miller, Jeremy Murphy, Matthew Pulver, Johan Råde,
      Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, Daryle
      Walker and Xiaogang Zhang<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../dists.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../dists.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="bernoulli_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
